How do I set up my @product=Product.find(params[:id]) to have a product_url?

Posted by montooner on Stack Overflow See other posts from Stack Overflow or by montooner
Published on 2010-06-16T20:17:58Z Indexed on 2010/06/16 20:22 UTC
Read the original article Hit count: 208

Filed under:
|
|

Trying to recreate { script/generate scaffold }, and I've gotten thru a number of Rails basics. I suspect that I need to configure default product url somewhere. But where do I do this?

Setup:

  1. Have: def edit { @product=Product.find(params[:id]) }
  2. Have edit.html.erb, with an edit form posting to action => :create
  3. Have def create { ... }, with the code redirect_to(@product, ...)
  4. Getting error: undefined method `product_url' for #< ProductsController:0x56102b0>

My def update:

def update
    @product = Product.find(params[:id])

    respond_to do |format|
      if @product.update_attributes(params[:product])
        format.html { redirect_to(@product, :notice => 'Product was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @product.errors, :status => :unprocessable_entity }
      end
    end
  end

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby